feat: handle host config changes in add_host method #788
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
问题描述
您好:
在我的使用过程中发现,当虚拟机的IP地址、端口等配置发生变化但vmid保持不变时,现有的
add_host方法无法检测到配置变更,导致Prometheus服务发现无法获取最新的配置信息。具体场景:
host_exists()方法会认为这是同一个host,不会更新解决方案
修改
add_host方法,当发现相同vmid但配置不同的host时,自动替换旧的配置,确保服务发现始终使用最新的配置信息。主要改进
is_same_config()方法进行配置比较,提高代码可读性技术实现
测试验证
测试输出: